package za.ac.wits.elen7045.persistence.datasource.sqlite;

import java.sql.ResultSet;
import java.sql.SQLException;
import za.ac.wits.elen7045.persistence.datasource.DataSourceRowEntry;
import za.ac.wits.elen7045.persistence.model.ServiceProvider;
import za.ac.wits.elen7045.persistence.model.ServiceProviderName;
import za.ac.wits.elen7045.persistence.util.ServiceProviderTableConstants;

public class ServiceProviderSQLiteDataSource extends SQLiteDataSource<ServiceProvider> implements ServiceProviderTableConstants {

	@Override
	protected ServiceProvider parseCurrentRowToObject(ResultSet resultSet) throws SQLException {
		ServiceProviderName serviceProviderType = ServiceProviderName.getServiceProviderTypeByName(resultSet.getString(SERVICE_PROVIDER_TYPE));
		ServiceProvider serviceProvider = new ServiceProvider(serviceProviderType, resultSet.getString(SERVICE_PROVIDER_NAME));
		serviceProvider.setId(resultSet.getInt(SERVICE_PROVIDER_ID));
		serviceProvider.setUrl(resultSet.getString(SERVICE_PROVIDER_URL));
		return serviceProvider;
	}

	@Override
	protected DataSourceRowEntry parseObjectToDataSourceRowEntry(ServiceProvider serviceProvider) throws SQLException {
		DataSourceRowEntry entry = new DataSourceRowEntry();
		entry.setValue(SERVICE_PROVIDER_ID, serviceProvider.getId());
		entry.setValue(SERVICE_PROVIDER_NAME, serviceProvider.getName());
		entry.setValue(SERVICE_PROVIDER_URL, serviceProvider.getUrl());
		entry.setValue(SERVICE_PROVIDER_TYPE, serviceProvider.getServiceProviderType().getName());
		return entry;
	}

}
